//
//  HJAdministratorIntroduceController.m
//  KaiChat
//
//  Created by lx on 2023/11/18.
//

#import "HJAdministratorIntroduceController.h"
#import "HJButton.h"

@interface HJAdministratorIntroduceController ()

@property (nonatomic, copy) NSString *message;
@property (nonatomic, weak) UIView *contentView;
@property (nonatomic, strong) UIImage *image;
@property (nonatomic, weak) UILabel *messageLabel;
@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic, weak) UIView *lastView;
@property (nonatomic, strong) UIFont *buttonFont;
@property (nonatomic, strong) UIFont *messageFont;

@end

 

@implementation HJAdministratorIntroduceController


- (void)showInController:(UIViewController *)controller {
   [controller presentViewController:self animated:NO completion:nil];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        
        self.messageFont = UIFontMake(14);
        self.buttonFont = UIFontMediumMake(16);
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    

    self.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0];

    UIView *contentView = [UIView addToView:self.view];
    contentView.addCornerRadius(10);
    contentView.backgroundColor = UIColor.whiteColor;
    _contentView = contentView;
    [contentView clipsToBounds];
    
    UIImageView *iconView = [UIImageView addToView:contentView];
    iconView.image = [UIImage imageNamed:@"administrator_icon"];
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(20);
        make.centerX.offset(0);
        make.height.width.offset(78);
    }];
 
    CGFloat contentWidth = 270;
 
    UILabel *titleLabel = [UILabel lableWithSuperView:contentView font:UIFontMediumMake(16) color:UIColor.tj_333333Color title:@"Group notice have the \nfollowing permissions:" textAlignment:NSTextAlignmentLeft];
    titleLabel.numberOfLines = 0;
    titleLabel.attributedText = [titleLabel.text titleMargin:3 alignment:NSTextAlignmentLeft];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(iconView.mas_bottom);
        make.left.offset(leftRightMargin);
        make.width.mas_lessThanOrEqualTo(contentWidth - leftRightMargin * 2);
    }];
    
    UILabel *messageLabel = [UILabel lableWithSuperView:contentView font:UIFontMake(14) color:UIColor.tj_868391Color title:@"1. Modify group information \n2. Post a group announcement \n3. Set up new member joining methods and approve new joining requests \n4. Delete group members" textAlignment:NSTextAlignmentLeft];
    messageLabel.numberOfLines = 0;
    messageLabel.attributedText = [messageLabel.text titleMargin:3 alignment:NSTextAlignmentLeft];
    [messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleLabel.mas_bottom).offset(8);
        make.centerX.offset(0);
        make.width.offset(contentWidth - leftRightMargin * 2);
    }];
    
    _lastView = messageLabel;
    _messageLabel = messageLabel;
    _titleLabel = titleLabel;
    
    
    UIView *bottomView = [UIView addToView:contentView];
    bottomView.backgroundColor = contentView.backgroundColor;
    [bottomView clipsToBounds];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.equalTo(messageLabel.mas_bottom).offset(15);
        make.left.right.inset(0);
        make.height.offset(50);
    }];
    

    UIView *bottomLineView = [UIView addToView:bottomView];
    bottomLineView.backgroundColor = UIColor.tj_separatorColor;
    [bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.inset(0);
        make.height.offset(lineHeight);
    }];
    
    
    HJButton *OKButton = [HJButton addToView:bottomView];
    [OKButton setTitle:@"OK" forState:UIControlStateNormal];
    [OKButton setTitleColor:UIColor.tj_mainColor forState:UIControlStateNormal];
    OKButton.titleLabel.font = self.buttonFont;
    OKButton.backgroundColor = UIColor.whiteColor;
    OKButton.addCornerRadius(10);
    [OKButton addTarget:self action:@selector(didClickOKButton:) forControlEvents:UIControlEventTouchUpInside];
    [OKButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.inset(2);
        make.center.offset(0);
        make.width.mas_equalTo(bottomView);
    }];
 
    _lastView = bottomView;
    
    [self.view layoutIfNeeded];
    
    CGFloat contentHeight = CGRectGetMaxY(_lastView.frame);
    contentView.frame = CGRectMake((KScreenWidth - contentWidth) * 0.5, (KScreenHeight - contentHeight) * 0.5 - 30, contentWidth, contentHeight);
    
}
 
- (void)didClickOKButton:(HJButton *)button {
 
    [UIView animateWithDuration:0.15 animations:^{
        self.view.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0];
        self.contentView.alpha = 0;
    } completion:^(BOOL finished) {
        [self dismissViewControllerAnimated:NO completion:^{
  
        }];
    }];
}
 

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    self.contentView.layer.transform = CATransform3DMakeScale(0.7, 0.7, 0.7);
    self.contentView.alpha = 0.7;
    [UIView animateWithDuration:0.25 delay:0 usingSpringWithDamping:0.70 initialSpringVelocity:0.8 options:UIViewAnimationOptionCurveEaseIn animations:^{
        self.contentView.alpha = 1;
        self.contentView.layer.transform = CATransform3DMakeScale(1, 1, 1);
        self.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.35];
    } completion:^(BOOL finished) {
        
    }];
}

- (UIModalPresentationStyle)modalPresentationStyle {
    return UIModalPresentationCustom;
}
 
@end




//    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"标题" message:@"消息" preferredStyle:UIAlertControllerStyleAlert];
//
//    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//        // 处理确定按钮点击事件
//    }];
//
//    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
//        // 处理取消按钮点击事件
//    }];
//
//    [alertController addAction:okAction];
//    [alertController addAction:cancelAction];
//
//    // 获取对按钮的引用
//    UIAlertAction *okButton = [alertController.actions objectAtIndex:0];
//    UIAlertAction *cancelButton = [alertController.actions objectAtIndex:1];
//
//    [okButton setValue:[UIColor greenColor] forKey:@"_titleTextColor"];
//    [cancelButton setValue:[UIColor orangeColor] forKey:@"titleTextColor"];
//
//
//    NSString * messageStr = @"真的要退出此账号么?";
//    //改变message的大小和颜色
//    NSMutableAttributedString *messageAtt = [[NSMutableAttributedString alloc] initWithString:messageStr];
//    [messageAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13.f] range:NSMakeRange(0, messageStr.length)];
//    [messageAtt addAttribute:NSForegroundColorAttributeName value:[UIColor cyanColor] range:NSMakeRange(0, messageStr.length)];
//    //KVC:改变字体(富文本)
//    [alertController setValue:messageAtt forKey:@"attributedMessage"];
//
//    NSString *titleStr = @"4y69461946";
//    NSMutableAttributedString *titleAtt = [[NSMutableAttributedString alloc] initWithString:titleStr];
//    [titleAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16.f] range:NSMakeRange(0, titleStr.length)];
//    [titleAtt addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(0, titleStr.length)];
//    //KVC:改变字体(富文本)
//    [alertController setValue:titleAtt forKey:@"attributedTitle"];
//
//
//    // 显示 UIAlertController
//    [self presentViewController:alertController animated:YES completion:nil];
//00008120-001C79243688C01E
